package com.magnificent.atlantis.client.data.message;

import com.magnificent.atlantis.client.data.message.messages.ClientMessage;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * User: Babanin
 * Date: 13.02.2009
 * Time: 17:19:47
 */
@XmlRootElement(name = "messages")
public class MessagesContainer {
    private List<ClientMessage> textMessages;

    public MessagesContainer() {
        textMessages = new ArrayList<ClientMessage>();
    }

    @XmlElement()
    public List<ClientMessage> getMessages() {
        return textMessages;
    }

    public List<ClientMessage> getMessages(MessageType messageType) {
        List<ClientMessage> result = new ArrayList<ClientMessage>();

        for (ClientMessage textMessage : textMessages) {
            if (textMessage.getMessageType() == messageType) {
                result.add(textMessage);
            }
        }

        return result;
    }

    public void addMessage(ClientMessage textMessage) {
        textMessages.add(textMessage);
    }

    public void removeMessage(ClientMessage textMessage) {
        textMessages.remove(textMessage);
    }

    public void setMessages(List<ClientMessage> textMessages) {
        this.textMessages = textMessages;
    }
}
